<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .vueApp {
            padding-bottom: 10px;
        }

        .container {
            margin: 15px;
            padding: 10px 10px 0 10px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .row {
            height: 50px;
            position: relative;
        }

        .row::after {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 1px;
            background: rgb(212, 212, 212);
            transform: translateY(0.5);
        }

        .key {
            font-size: 15px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
        }

        .input {
            font-size: 15px;
            text-align: right;
        }

        .input::placeholder {
            font-size: 15px;
            font-weight: 400;
            color: rgba(191, 191, 191, 1);
        }

        .text-gray {
            font-size: 15px;
            font-weight: 400;
            color: rgba(191, 191, 191, 1);
            text-align: right;
        }

        .text-black {
            font-size: 15px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
            text-align: right;
        }

        .arrow {
            width: 17px;
            height: 16px;
            margin-left: 8px;
        }

        .title {
            font-size: 15px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
            margin-top: 16px;
        }

        .textarea {
            width: 100%;
            margin-top: 10px;
            outline: none;
            font-size: 15px;
            font-weight: 400;
            line-height: 20px;
        }

        .textarea::placeholder {
            font-size: 15px;
            font-weight: 400;
            color: rgba(191, 191, 191, 1);
        }

        .btn {
            width: 210px;
            height: 46px;
            background: url("../../image/ui/btn.png");
            background-size: 100% 100%;
            margin: 45px auto 0 auto;
            font-size: 18px;
            font-weight: 600;
            color: rgba(124, 69, 0, 1);
            text-align: center;
            line-height: 44px;
            box-shadow: 0px 5px 7px 0px rgba(11, 126, 193, 0.53);
            border-radius: 22px;
        }

        .icon-default {
            width: 82px;
            height: 50px;
        }

        .clear-border::after {
            display: none;
        }

        .last {
            padding-left: 10px;
            padding-top: 0;
            padding-right: 0;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="container" id="tel_login">
            <div class="row" data-flex="cross:center">
                <div class="key">收货人</div>
                <input class="input" v-model="name" data-flex-box="1" type="text" placeholder="请输入收货人">
            </div>
            <div class="row" data-flex="cross:center">
                <div class="key">收货人电话</div>
                <input class="input" v-model="phoneNumber" data-flex-box="1" spellcheck="false" type="tel" maxlength="11"
                    data-type="_telphone" data-verify="true" data-null="true" data-regular="true" name="手机号"
                    placeholder="请输入收货人电话">
            </div>
            <div class="row" data-flex="cross:center" @click="selCity()">
                <div class="key">所在城市</div>
                <input class="input" type="text" data-flex-box="1" readonly="" :value="fullAddress"
                    placeholder="请选择您所在的城市">
                <div class="arrow">
                    <img src="../../image/ui/arrow_right_2.png" alt="">
                </div>
            </div>
            <div class="title">详细地址</div>
            <textarea class="textarea" v-model="detailAddress" maxlength="32" placeholder="请输入详细地址" rows="5"></textarea>
        </div>
        <div class="container last">
            <div class="row clear-border" data-flex="main:justify cross:center">
                <div class="key">设为默认地址</div>
                <img class="icon-default" :src="isDefault ? '../../image/ui/on.png' : '../../image/ui/off.png'" @click="isDefault = !isDefault;" alt="">
            </div>
        </div>
        <div class="btn" @click="submitFn()">提交</div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/service/service-verify.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var addressCode = {};
    var param = {
        item: {}
    };
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        param = api.pageParam;
        param.item = param.item || {};
        if (param.item) {
            addressCode.province = param.item.province;
            addressCode.city = param.item.city;
            addressCode.region = param.item.region;
        }
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                name: param.item.name || '',
                phoneNumber: param.item.phoneNumber || '',
                fullAddress: param.item.schoolAddress || '',
                detailAddress: param.item.detailAddress || '',
                isDefault: param.item.defaultStatus == 1 ? true : false
            }
        });
    }

    function selCity() {
        fnOpenFrame({
            name: 'address_picker',
            url: '../mine/area_layer.html',
            rect: {
                x: 0, y: 0, w: 'auto', h: 'auto'
            },
            pageParam: {
                frameName: api.frameName,
                winName: api.winName,
                provinceCode: addressCode.province,
                cityCode: addressCode.city,
                countyCode: addressCode.region
            }
        })
    }

    // 
    function isAllTrue() {
        return vm.name && vm.phoneNumber && vm.fullAddress && vm.detailAddress ? true : false
    }

    function fnSetArea(provinceCode, cityCode, countyCode, areaName) {
        addressCode.province = provinceCode;
        addressCode.city = cityCode;
        addressCode.region = countyCode;
        vm.fullAddress = areaName;
    }
    // 如果 param 等于空对象,则说明用户是新增地址
    // 否则说明用户是编辑地址
    function submitFn() {
        if(!isAllTrue()) {
            fnToast('不能有空的必填项');
            return;
        }
        if (fnVerify("tel_login")) {
            var url = '';
            var params = {
                'entityName': 'umsMemberReceiveAddress',
                
                "name": vm.name,
                "phoneNumber": vm.phoneNumber,
                "detailAddress": vm.detailAddress,
                "defaultStatus": vm.isDefault ? '1' : '0'
            };
            Object.assign(params, addressCode);
            var msg = '';
            if (!param.item.id) {
                url = 'common/insert';
                msg = '添加成功';
            } else {
                url = 'common/updateById';
                params.id = param.item.id;
                msg = '编辑成功';
            }
            var callback = function (data) {
                fnToast(msg);
                api.execScript({
                    name: param.winName,
                    frameName: param.frmName,
                    script: 'getPageData("headerRefreshing");'
                })
                api.closeWin();
                // status 为200时,只返回data
            };
            POST(url, params, callback);
        }
    }
</script>

</html>